package vn.edu.saigontech.ncms.web.study;

import vn.edu.saigontech.ncms.model.info.Offering;
import vn.edu.saigontech.ncms.model.info.Student;
import vn.edu.saigontech.ncms.service.OfferingService;
import vn.edu.saigontech.ncms.service.StudentService;
import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateReceiptAction extends AbstractValidator {
	
	private Long id;
	private String date;
	private String fromDate;
	private String toDate;
	private Long offeringId;
	private String fee;
	private Long cashierId;
	private Long studentId;

	@Override
	public String check() {
		if(Checker.isNull(this.studentId)) {
			this.sendKeyError("validator.required", "student");
		}
		if(Checker.isNull(this.offeringId)) {
			this.sendKeyError("validator.required", "offering");
		}
		if(Checker.isNull(this.id)) {
			Offering offering = OfferingService.INSTANCE.findById(offeringId);			
			Student student = StudentService.INSTANCE.findById(this.studentId);
			if(offering.contains(student)) {
				this.sendKeyError("validator.exist", "student");
			}
		}
		if(Checker.isEmpty(date)) {
			this.sendKeyError("validator.required", "date");
		}
		if(!Checker.isDate(this.date, this.i18n("format.date"))) {
			this.sendKeyError("validator.invalid", "date");
		}
		if(Checker.isEmpty(this.fee)) {
			this.sendKeyError("validator.required", "fee");
		}
		if(!Checker.isDouble(this.fee)) {
			this.sendKeyError("validator.invalid", "fee");
		}
		if(!Checker.isPositive(this.fee)) {
			this.sendKeyError("validator.invalid", "fee");
		}
		if(Checker.isNull(this.cashierId)) {
			this.sendKeyError("validator.required", "cashier");
		}
		return this.toSuccess();
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getFee() {
		return fee;
	}

	public void setFee(String fee) {
		this.fee = fee;
	}

	public Long getOfferingId() {
		return offeringId;
	}

	public void setOfferingId(Long offeringId) {
		this.offeringId = offeringId;
	}

	public Long getCashierId() {
		return cashierId;
	}

	public void setCashierId(Long cashierId) {
		this.cashierId = cashierId;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public Long getStudentId() {
		return studentId;
	}

	public void setStudentId(Long studentId) {
		this.studentId = studentId;
	}

	public String getFromDate() {
		return fromDate;
	}

	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}

	public String getToDate() {
		return toDate;
	}

	public void setToDate(String toDate) {
		this.toDate = toDate;
	}
}
